package org.bata.service;

import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import org.bata.domain.User;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: omenk
 * Date: 5/17/11
 * Time: 11:04 PM
 * To change this template use File | Settings | File Templates.
 */
public class BataLogin implements LoginService{
    @Override
    public List<User> login(String username, String password) {
        try{
            WebClient client = new WebClient();
            HtmlPage page  = client.getPage("http://web.batavia-air.com/MyPage/login.php");
            HtmlForm form = page.getFormByName("loginForm");

            form.getInputByName("useridmp").setValueAttribute(username);
            form.getInputByName("passwordmp").setValueAttribute(password);

            HtmlSubmitInput button = form.getInputByValue("sign in!");

             final HtmlPage page2 = button.click();
            // logger.debug("Page 2 : " + page2.getTitleText());
            System.out.println(page2.getTitleText());

        } catch (MalformedURLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return  null;

    }

    @Override
    public boolean cekLogin(String username, String password) {



        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }
}
